<template>
  <t-drawer :visible="visible" @close="$emit('close')"
            title="新增参数">
    <t-form ref="addForm" :form-desc="formDesc" :form-data="formData">

    </t-form>
    <el-row slot="footer">
      <el-button size="small" type="primary" icon="el-icon-check" @click="save">保存</el-button>
      <el-button size="small" icon="el-icon-refresh-right" @click="">重置</el-button>
    </el-row>
  </t-drawer>
</template>

<script>


import request from "../../../../../utils/request";

export default {
  props: {
    visible: {
      type: Boolean,
      default() {
        return false
      }
    }
  },
  data() {
    return {
      formDesc: {
        nickName: {
          label: '昵称',
          type: 'input',
          rules: [
            {required: true, message: '该项必填', trigger: 'blur'},
            {min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur'},
            {pattern: /^[\u4E00-\u9FA5A-Za-z0-9_]+$/, message: '由数字、字母、下划线组成', trigger: 'blur'},
          ],
        },
        account: {
          label: '登录账号',
          type: 'input',
          rules: [
            {required: true, message: '该项必填', trigger: 'blur'},
            {min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur'},
            {pattern: /^[A-Za-z0-9_]+$/, message: '由中文、数字、字母、下划线组成', trigger: 'blur'},
          ],
        },
      },
      oldFormData: {},
      formData: {}
    }
  },
  methods: {
    save() {
      this.$refs['addForm'].$refs['form'].validate((valid) => {
        if (valid) {
          request({
            url: '/sys/account/add',
            method: 'post',
            data: this.formData
          }).then(data => {
            this.$message.success("保存成功！")
            this.$emit('close')
            this.$emit('saveSuccess')
            this.$refs['addForm'].$refs['form'].resetFields()
          })
        } else {
          return false;
        }
      });
    }
  },
}
</script>

<style lang="less" scoped>

</style>